<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>访问属性</title>
    <script type="text/javascript" src="../js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("img").click(function () {
                // console.log($("img")[0].src);
                // attr("属性名"):取值
                // attr("属性名","属性值"):赋值
                // removeAttr("属性名"):移除指定属性
                console.log($("img").attr("src"));
                console.log($("img").attr("alt"));
                console.log($("img").attr("title"));
                $("img").attr("src","../images/4.jpg");
                $("img").attr("title","今天天气真热");
                $("img").removeAttr("src");
            });
            $("#username").blur(function(){
                console.log("type属性:"+$(this).attr("type"));
                console.log("id属性:"+$(this).attr("id"));
                // 1.9之后失效
                console.log("value属性:"+$(this).attr("value"));
                // 需要将attr换成prop
                console.log("value属性:"+$(this).prop("value"));
            });
        });
    </script>
</head>
<body>
<img src="../images/heihei.gif" alt="图片加载失败" title="今天天气不错">
用户名:<input type="text" id="username" value="admin"><br>
</body>
</html>